import logging
import time

from tools.base_page import BasePage
from selenium.webdriver import  ActionChains

class FormWrite(BasePage):
    def form_write(self):
        self.verify_wait_click(self.only_read_yaml('../data/form_write.yaml','news'))
        ele = self.elements(self.only_read_yaml('../data/form_write.yaml','news'))[0]
        ActionChains(self.driver).move_to_element(ele).perform()
        self.open_yaml_element('../data/form_write.yaml','news_form')
        self.verify_wait_click(('css selector','.operation-content'))
        item  = self.driver.find_element_by_css_selector('.operation-content')  #  目标节点
        # 初始节点
        node_type_first = self.find(self.only_read_yaml('../data/form_write.yaml','node_type_first'))
        node_type_two = self.find(self.only_read_yaml('../data/form_write.yaml','node_type_two'))
        # # 移动element到目标item
        ActionChains(self.driver).drag_and_drop(node_type_first, item).perform()
        ActionChains(self.driver).drag_and_drop(node_type_two, item).perform()
        return self


    def news_save(self):

        self.open_yaml_element('../data/form_write.yaml','save',is_elements=1,ele_num=3) # 先点击保存
        self.open_yaml_element('../data/form_write.yaml','dloption',is_elements=1,ele_num=0)
        self.selector_execute_script('body>div:nth-of-type(5)>div>div>div>ul>li')
        self.open_yaml_element('../data/form_write.yaml','dloption',is_elements=1,ele_num=1)
        self.selector_execute_script('body>div:nth-of-type(6)>div>div>div>ul>li')
        self.open_yaml_element('../data/form_write.yaml','confirm',is_elements=1,ele_num=5)  # 确定
        return self

    def search_name(self):
        first_bg_name = self.find(self.only_read_yaml('../data/form_write.yaml','list_bd_name')).text
        self.open_yaml_element('../data/form_write.yaml','bd_search_input',content=first_bg_name)
        self.open_yaml_element('../data/form_write.yaml','search_locator')
        self.verify_wait_click(self.only_read_yaml('../data/form_write.yaml','search_res_total'))
        return self.find(self.only_read_yaml('../data/form_write.yaml','search_res_total')).text
